import 'babel-polyfill'
import Es6Promise from 'es6-promise'
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import '@/router/permission'; //路由守卫
import store from './store'
import * as Fetch from '@/service/fetch'
import selfFunc from '@/utils/common'
import './assets/css/index.css'
import './plugins/vant.js'

Es6Promise.polyfill()

Vue.prototype.$http = Fetch

Vue.prototype.$selfFunc = selfFunc

Vue.config.productionTip = false

if (navigator.userAgent.indexOf('appOpen') > -1) {
    window.apiready = function() {
        Vue.prototype.$headerH = api.safeArea.top ? (api.safeArea.top - 1) : 0
        var headerH = Vue.prototype.$headerH
        Vue.mixin({
            mounted: function() {
                this.$nextTick(() => {
                    if (document.getElementsByClassName('headerBox') && document.getElementsByClassName('headerBox')[0]) {
                        document.getElementsByClassName('headerBox')[0].style.paddingTop = headerH + 'px'
                    }
                    if (document.getElementsByClassName('pageContentPaddingT') && document.getElementsByClassName('pageContentPaddingT')[0]) {
                        document.getElementsByClassName('pageContentPaddingT')[0].style.paddingTop = `calc(46px + ${headerH}px)`
                    }
                    if (document.getElementsByClassName('pageContentPaddingT2') && document.getElementsByClassName('pageContentPaddingT2')[0]) {
                        document.getElementsByClassName('pageContentPaddingT2')[0].style.paddingTop = `calc(1.03rem + ${headerH}px)`
                    }
                })
            }
        })

        api.addEventListener({
            name: 'resume'
        }, function(ret, err) {
            api.removeLaunchView({
                animation: {
                    type: 'fade',
                    duration: 300
                }
            })
        })

        new Vue({
            data() {
                return {
                    eventBus: new Vue()
                }
            },
            router,
            store,
            render: h => h(App),
        }).$mount("#app");
    }
} else {
    if (window.api == undefined) {
        Vue.prototype.$headerH = 0
        new Vue({
            data() {
                return {
                    eventBus: new Vue()
                }
            },
            router,
            store,
            render: h => h(App),
        }).$mount("#app");
    }
}